package com.googlecode.jtoy.patterns.facade;

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * @author shangxj
 * @date Jun 19, 2011 7:24:51 PM
 */
public class FacadeTest {

	@Test
	public void testNotFacade() {

		KeysDrawer keysDrawer = new KeysDrawer();
		FilesDrawer filesDrawer = new FilesDrawer();

		Object file = null;

		// 1.先打开装钥匙的抽屉
		keysDrawer.open();
		// 2.是否真的打开了
		if (keysDrawer.isOpen()) {

			// 3.取钥匙
			Integer key = keysDrawer.getKey("filesDrawer");
			// 4.如果取到钥匙了
			if (key != null) {

				// 5.用取到的钥匙打开装文件的抽屉
				filesDrawer.open(key);
				// 6.是否真的打开了
				if (filesDrawer.isOpen()) {

					// 7.取文件
					file = filesDrawer.getFile();
					// 8.关闭装文件的抽屉
					filesDrawer.close();

					// 9.放回钥匙
					keysDrawer.putKey(key);
					// 10.关闭装钥匙的抽屉
					keysDrawer.close();
				}
			}
		}

		assertNotNull(file);
	}

	@Test
	public void testFacade() {

		Facade facade = new Facade();

		Object file = facade.getFile();

		assertNotNull(file);
	}

}
